package com.dtease.agent.biz.resource.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dtease.agent.biz.resource.dto.BasStorageDTO;
import com.dtease.agent.biz.resource.entity.BasStorage;
import com.dtease.agent.biz.resource.mapper.BasStorageMapper;
import com.dtease.agent.biz.resource.service.IBasStorageService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 数据源表 服务实现类
 * </p>
 *
 * @author chentl
 * @since 2025-05-07
 */
@DS("resource")
@Slf4j
@Service
public class BasStorageServiceImpl extends ServiceImpl<BasStorageMapper, BasStorage> implements IBasStorageService {

    @Override
    public List<BasStorageDTO> listByTypes(List<Integer> storageTypeList) {
        if(CollectionUtils.isEmpty(storageTypeList)){
            log.error("storageTypeList is empty");
            return Collections.emptyList();
        }
        List<BasStorageDTO> basStorages = baseMapper.listByTypes(storageTypeList);
        return basStorages;
    }

    @Override
    public String selectTableTags(String tenantId, String storageId, String databaseName, String tableName) {
        if(StringUtils.isAnyEmpty(tenantId, storageId, databaseName, tableName)){
            log.error("tenantId or storageId or databaseName or tableName is empty");
            return "";
        }
       String tags = baseMapper.selectTableTags(tenantId, storageId, databaseName, tableName);
        return tags;
    }
}
